package edu.neumont.MillerK.Android;

import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

public class AuthenticationActivity extends Activity {
	private Button submitButton;
	private EditText usernameEditText;
	private EditText passwordEditText;
	/** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.authentication);
        submitButton = (Button)findViewById(R.id.SubmitButton);
        submitButton.setOnClickListener(new OnClickListener() {
			
			public void onClick(View v) {
		        usernameEditText = (EditText)findViewById(R.id.UsernameEditText);
		        passwordEditText = (EditText)findViewById(R.id.PasswordEditText);
				SharedPreferences sharedPref = getSharedPreferences("default", MODE_PRIVATE);
				SharedPreferences.Editor prefEditor = sharedPref.edit();
				prefEditor.putString("features", "222222");
				prefEditor.putString("username", usernameEditText.getText().toString());
				prefEditor.putString("password", passwordEditText.getText().toString());
				prefEditor.commit();
				
				Toast.makeText(AuthenticationActivity.this, "Login saved", Toast.LENGTH_LONG).show();
				Intent intent = new Intent(getBaseContext(), MainService.class);
				intent = new Intent("edu.neumont.MillerK.Android.MainService");
				intent.putExtra("screamerOn", false);
				intent.setClass(AuthenticationActivity.this, MainService.class);
				startService(intent);
				intent.setClass(AuthenticationActivity.this, MainActivity.class);
				startActivity(intent);
			}
		});
    }
}
